package com.haoting.mamba.team.service.impl;

import com.haoting.mamba.team.entity.TeamInformationEntity;
import com.haoting.mamba.team.entity.vo.ZhanJI;
import com.haoting.mamba.team.service.TeamInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.haoting.common.utils.PageUtils;
import com.haoting.common.utils.Query;

import com.haoting.mamba.team.dao.TeamBasicdateDao;
import com.haoting.mamba.team.entity.TeamBasicdateEntity;
import com.haoting.mamba.team.service.TeamBasicdateService;


@Service("teamBasicdateService")
public class TeamBasicdateServiceImpl extends ServiceImpl<TeamBasicdateDao, TeamBasicdateEntity> implements TeamBasicdateService {

    @Autowired
    TeamInformationService teamInformationService;

    @Override
    public List<ZhanJI> xizhanji() {
        return baseMapper.xizhanji();
    }

    @Override
    public List<ZhanJI> dongzhanji() {
       return baseMapper.dongzhanji();
    }

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<TeamBasicdateEntity> wrapper =  new QueryWrapper<>();
        if(!String.valueOf(params.get("query")).equals("")){
            wrapper.eq("stage",params.get("query"));
        }
        if(!String.valueOf(params.get("key")).equals("")){
            TeamInformationEntity one =teamInformationService.getOne(new QueryWrapper<TeamInformationEntity>()
                    .like("name", params.get("key")));
            String teamId = one.getId();
            wrapper.like("team_id",teamId);
        }
        IPage<TeamBasicdateEntity> page = this.page(
                new Query<TeamBasicdateEntity>().getPage(params),
                wrapper
        );
        for (int i=0;i<page.getRecords().size();i++){
            TeamInformationEntity byId = teamInformationService.getById(page.getRecords().get(i).getTeamId());
            String name = byId.getName();
            page.getRecords().get(i).setTeamId(name);
        }
        return new PageUtils(page);
    }

}